import service from '@/utils/request.js'

/**
 * 获取所有角色预设列表
 * @returns {Promise} - 返回角色预设列表
 */
export const getRolePresetList = (params = {}) => {
  // 构建请求参数
  const requestParams = {}
  
  // 角色名称搜索
  if (params.roleName && params.roleName.trim()) {
    requestParams.roleName = params.roleName.trim()
  }
  
  // 分页参数
  if (params.startPage !== undefined) {
    requestParams.startPage = params.startPage
  }
  if (params.pageSize !== undefined) {
    requestParams.pageSize = params.pageSize
  }
  
  // 是否私有参数
  if (params.isPrivate !== undefined) {
    requestParams.isPrivate = params.isPrivate
  }
  
  return service({
    url: '/role-preset/list',
    method: 'GET',
    params: requestParams,
    setting: {
      isToken: true
    }
  });
};

/**
 * 根据ID获取角色预设
 * @param {string} id - 角色预设ID
 * @returns {Promise} - 返回角色预设详情
 */
export const getRolePresetById = (id) => {
  return service({
    url: `/role-preset/find/${id}`,
    method: 'GET',
    setting: {
      isToken: true
    }
  });
};

/**
 * 创建新的角色预设
 * @param {Object} rolePreset - 角色预设对象
 * @returns {Promise} - 返回创建结果
 */
export const createRolePreset = (rolePreset) => {
  return service({
    url: '/role-preset',
    method: 'POST',
    data: rolePreset,
    setting: {
      isToken: true
    }
  });
};

/**
 * 更新角色预设
 * @param {Object} rolePreset - 角色预设对象
 * @returns {Promise} - 返回更新结果
 */
export const updateRolePreset = (rolePreset) => {
  return service({
    url: '/role-preset',
    method: 'PUT',
    data: rolePreset,
    setting: {
      isToken: true
    }
  });
};

/**
 * 删除角色预设
 * @param {string} id - 角色预设ID
 * @returns {Promise} - 返回删除结果
 */
export const deleteRolePreset = (id) => {
  return service({
    url: `/role-preset/${id}`,
    method: 'DELETE',
    setting: {
      isToken: true
    }
  });
};
